home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / qbware.exe / LOOK.BAS < prev    next >
Encoding:
BASIC Source File  |  1990-11-30  |  4.9 KB  |  175 lines

  1. DECLARE SUB SetDirectory (Dir$)
  2. DECLARE SUB FindFile (Root.Dir$, Target.File$, Total.Files%, Tot.Fsize#)
  3. DECLARE SUB GetDirectory (Dir$)
  4. DECLARE SUB FlFind (FlSpec$, BYVAL addr%)
  5. '*****************************************************************************
  6.  
  7. 'Copyright (c) 1987,1988 Marcel Madonna
  8.  
  9. 'LOOK.BAS shows the use of some of the DOS file management services and
  10. '  recursive subroutine usage.
  11. 'This program will scan all directories in a disk, looking for a file.
  12. '
  13. ' ********************* N O T E *************************
  14. '
  15. 'This program cannot be used from the DOS prompt without Microsoft
  16. 'QuickBasic V4.0 and a registered copy of QBWARE.
  17. '
  18. 'To compile it, at the DOS prompt type:
  19.  
  20. '               bc look;
  21. '               link /ex /noe look,,,brun40 qbware;
  22. '               del look.obj
  23. '               del look.map
  24.  
  25. 'To run it fromthe QuickBasic development environment, type:
  26. '
  27. '               qb look /l qbware
  28. '               [Shift] + F5
  29.  
  30. 'To execute LOOK just type "LOOK" followed by a file specification at the
  31. 'DOS prompt
  32.  
  33. 'For Example:
  34.  
  35. '       LOOK *.Bak
  36.  
  37. 'will find all files on the current drive with an extension of BAK
  38.  
  39. '*****************************************************************************
  40.  
  41.     OPTION BASE 1
  42.     CLEAR , , 5000                  'Need a large stack
  43.     CLS
  44.     PRINT "Look - Version 1.0  (C) Copyright 1987,1988 AJM Software"
  45.     Target.File$ = COMMAND$
  46.     IF Target.File$ = "" THEN
  47.         INPUT "Enter a Filename:", Target.File$
  48.     END IF
  49.  
  50.     Dir$ = SPACE$(64)               'Initialize for ALC routine
  51.     CALL GetDirectory(Dir$)         'Save current directory
  52.     Root.Dir$ = "\"                 'Start with the root directory
  53.  
  54.     CALL FindFile(Root.Dir$, Target.File$, Tot.Files%, Tot.Fsize#)
  55.  
  56.     CALL SetDirectory(Dir$)         'Restore directory
  57.  
  58.  
  59.  
  60.     PRINT "Total Files";
  61.     PRINT TAB(13); Tot.Files%;
  62.     PRINT TAB(40); "Total Bytes";
  63.     PRINT TAB(55); Tot.Fsize#
  64.     END
  65.  
  66.     SUB FindFile (Target.Dir$, Target.File$, Tot.Files%, Tot.Fsize#)
  67.  
  68.     CALL SetDirectory(Target.Dir$)          'Change to new directory
  69.  
  70.     PRINT "...Searching " + Target.Dir$
  71.     GOTO A1000.Start.Search                 'Skip Array init routine
  72.  
  73. A0500.Dim.Array:        'Leave this here so we can reference the array
  74.  
  75.     REDIM DirList$(Count%)                  'Dimension the array fo FLFIND
  76.     FOR x% = LBOUND(DirList$) TO Count%     'Initialize each element of array
  77.         DirList$(x%) = SPACE$(40)       'to 40 blanks
  78.     NEXT
  79.     RETURN
  80.  
  81. A1000.Start.Search:
  82.  
  83.     FlSpec$ = Target.File$ + CHR$(0)        'Make it an ASCIIZ string
  84.  
  85.     CALL Flcnt(FlSpec$, Count%)             'Get a count of matching files
  86.  
  87.     IF Count% <> 0 THEN                     'Did we get any hits?
  88.         GOSUB A0500.Dim.Array
  89.         CALL FlFind(FlSpec$, VARPTR(DirList$(LBOUND(DirList$))))
  90.     ELSE
  91.         GOTO A2000.NextDir              '...No - search for sub-directories
  92.     END IF
  93.  
  94. '   Each element of the array will be broken down into components
  95. '   The layout of each item is:
  96.  
  97. '       Pos.    Description
  98.  
  99. '       1-5     File Attributes
  100. '       6-13    File creation time (HH:MM:SS)
  101. '       14-23   File creation date (MM-DD-YYYY)
  102. '       24-25   Low order file size
  103. '       26-27   High order file size
  104. '       28-39   File name
  105.  
  106.     FOR x% = LBOUND(DirList$) TO Count%
  107.  
  108.         XFname$ = MID$(DirList$(x%), 28, 12)
  109.         Fattr$ = MID$(DirList$(x%), 1, 5)
  110.         ftime$ = MID$(DirList$(x%), 6, 8)
  111.         fdate$ = MID$(DirList$(x%), 14, 10)
  112.         Fsize1# = CVI(MID$(DirList$(x%), 26, 2)) * 65536
  113.         Fsize2# = CVI(MID$(DirList$(x%), 24, 2))
  114.         IF Fsize2# < 0 THEN
  115.             Fsize2# = 65536 + Fsize2#
  116.         END IF
  117.         Fsize# = Fsize1# + Fsize2#
  118.         PRINT TAB(6); XFname$;
  119.         PRINT TAB(22); Fattr$;
  120.         PRINT TAB(28); fdate$;
  121.         PRINT TAB(40); ftime$;
  122.         PRINT TAB(50); Fsize#
  123.         Tot.Files% = Tot.Files% + 1
  124.         Tot.Fsize# = Tot.Fsize# + Fsize#
  125.     NEXT
  126.  
  127. A2000.NextDir:
  128.  
  129.     FlSpec$ = "*.*" + CHR$(0)               'Get all files in this directory
  130.  
  131.     CALL Flcnt(FlSpec$, Count%)             'Get a count
  132.  
  133.     IF Count% <> 0 THEN                     'Any files this directory?
  134.         GOSUB A0500.Dim.Array
  135.         CALL FlFind(FlSpec$, VARPTR(DirList$(LBOUND(DirList$))))
  136.     ELSE
  137.         EXIT SUB                        '...No - just exit
  138.     END IF
  139.  
  140.     FOR x% = LBOUND(DirList$) TO Count%
  141.         Fattr$ = MID$(DirList$(x%), 1, 5)
  142.         XFname$ = MID$(DirList$(x%), 28, 12)
  143.         IF INSTR(Fattr$, "D") <> 0 AND LEFT$(XFname$, 1) <> "." THEN
  144.             IF Target.Dir$ = "\" THEN
  145.                 NextDir$ = "\" + XFname$
  146.             ELSE
  147.                 NextDir$ = Target.Dir$ + "\" + XFname$
  148.             END IF
  149.             CALL FindFile(NextDir$, Target.File$, Tot.Files%, Tot.Fsize#)
  150.         END IF
  151.     NEXT
  152.  
  153.     EXIT SUB
  154.  
  155.     END SUB
  156.  
  157.     SUB GetDirectory (Dir$) STATIC
  158.     CALL FlGDir(Dir$)                'Get current directory
  159.     Dir$ = "\" + Dir$                'Make it DOS format
  160.     END SUB
  161.  
  162.     SUB SetDirectory (Dir$) STATIC
  163.  
  164.     Current.Dir$ = Dir$ + CHR$(0)
  165.     CALL FlCDir(Current.Dir$, Rc%)          'Change current directory to root
  166.     IF Rc% <> 0 THEN
  167.         CLS
  168.         PRINT "Cannot change to directory " + Dir$
  169.         PRINT "Error code", Rc%
  170.         END
  171.     END IF
  172.  
  173.     END SUB
  174.  
  175.